package com.securitydemo.config;

import com.securitydemo.config.serializer.CustomOffsetDateTimeJsonSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.time.OffsetDateTime;
import java.util.List;

/**
 * springboot 全局转换器 的三种实现
 *
 * 1、 注入jackson2ObjectMapperBuilderCustomizer bean
 * 2、 实现configureMessageConverters 转换器
 * 3、JacksonConfig 实现objectMapper
 */

//@Configuration
public class ConvertConfiguration implements WebMvcConfigurer {



   // @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return builder ->
                builder.serializerByType(OffsetDateTime.class, new CustomOffsetDateTimeJsonSerializer());

    }



    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
/*        final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        ObjectMapper objectMapper = new ObjectMapper();
        SimpleModule simpleModule = new SimpleModule();
        simpleModule.addSerializer(OffsetDateTime.class, new CustomOffsetDateTimeJsonSerializer());
        objectMapper.registerModule(simpleModule);
        converter.setObjectMapper(objectMapper);
        converters.add(0, converter);*/
    }
}
